package io;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import config.Config;
import crono.Cronometro;

public class LocalFileCopyIO {

	public static void main(String[] args) {
		Cronometro timer = new Cronometro();
		timer.start();

		try (DataInputStream dis = new DataInputStream(new FileInputStream(
				new File(Config.INPUT_FILE)));
				DataOutputStream dos = new DataOutputStream(
						new FileOutputStream(new File(Config.OUTPUT_FILE_IO)));) {
			byte[] buf = new byte[Config.LOCAL_BUF_SIZE];
			int size = Integer.MAX_VALUE;
			while (size > 0) {
				size = dis.read(buf);
				if (size > 0) {
					dos.write(buf, 0, size);
				}
			}
		} catch (FileNotFoundException e) {
			System.err.println("File not found. Details: " + e.getMessage());
		} catch (IOException e) {
			System.err.println("Error occured, while copying file. Details: "
					+ e.getMessage());
		}

		timer.stop();
		timer.print("IO. Copy local file");
	}

}
